package com.watering.plan;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.ImageView;
import android.widget.Toast;

public class VacationRestrictions  extends Activity {
	public int day_s;
	public int mon_s;
	public int day_f;
	public int mon_f;
	DatePicker dp1;
	DatePicker dp2;
	Toast ts;
	Base bs;
	
	public void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
         setContentView(R.layout.vacationrestriction);
         
         ts =  Toast.makeText(this, R.string.vacation_help, Toast.LENGTH_SHORT);
         ts.setDuration(Toast.LENGTH_LONG);
         
         ImageView img = (ImageView)findViewById(R.id.helpbutton);
         img.setOnClickListener(new OnClickListener() {
	         public void onClick(View v) {
	        	ts.show();
	         }
	     });
         
         dp1 = new DatePicker(this);
         dp1 = (DatePicker)findViewById(R.id.DatePicker01);
         dp2 = new DatePicker(this);
         dp2 = (DatePicker)findViewById(R.id.DatePicker02);
         bs = new Base(this);
         
	     Button SaveButton = (Button) findViewById(R.id.Button01);
	     SaveButton.setOnClickListener(new OnClickListener() {
	         public void onClick(View v) {
	        	 day_s = dp1.getDayOfMonth();
	        	 day_f = dp2.getDayOfMonth();
	        	 mon_s = dp1.getMonth();
	        	 mon_f = dp2.getMonth();
		    	    try{
	    				bs.createDataBase();
	    				bs.openDataBase();
	    			//	ts.setText("ceva" +bs.getRestriction());
	    				bs.addRestriction(0,0,0,0,0, day_s, mon_s, day_f, mon_f);
	    				bs.close();
	    				
	    		}catch(Exception e){
	    			ts.setText(e.toString());
	    			ts.show();
	    		}
	    		finish();
	         }
	     });
	}  
}